package com.notime.web.converter;

import java.util.Date;
import java.util.Locale;

import org.joda.time.LocalDate;

import com.vaadin.data.util.converter.Converter;

/**
 * Converts dates from java.util.Date to org.joda.time.LocalDate representation
 */
public class DateToLocalDateConverter implements Converter<Date, LocalDate> {

  /**
	 * 
	 */
	private static final long serialVersionUID = 7814487812855391340L;

@Override
  public LocalDate convertToModel(Date value, Class<? extends LocalDate> targetType, Locale locale)
      throws com.vaadin.data.util.converter.Converter.ConversionException {
    return new LocalDate(value);
  }

  @Override
  public Date convertToPresentation(LocalDate value, Class<? extends Date> targetType, Locale locale)
      throws com.vaadin.data.util.converter.Converter.ConversionException {
    return value.toDate();
  }

  @Override
  public Class<LocalDate> getModelType() {
    return LocalDate.class;
  }

  @Override
  public Class<Date> getPresentationType() {
    return Date.class;
  }

}
